#ifndef __CCMS_NR_CPU_STATS_H__
#define __CCMS_NR_CPU_STATS_H__

/**
 * @file ccms/nr/cpu_stats.h
 *
 * CpuStats class header file.
 */

#include "ccms/nr/types.h"
#include <linux/version.h>

namespace ccms {
namespace nr {

/**
 * CpuTime holds times the CPU spent in particular CPU modes.
 */
typedef struct CpuTimeS {
    unsigned long long user;    /**< user mode */
    unsigned long long nice;    /**< nide mode */
    unsigned long long system;  /**< system mode */
    unsigned long long idle;    /**< idle */
    unsigned long long iowait;  /**< iowait mode */
    unsigned long long irq;     /**< irq mode */
    unsigned long long softirq; /**< softirq mode */
    unsigned long long steal;   /**< steal mode */
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24))
    unsigned long long guest;   /**< guest mode */
#endif
} CpuTime;

/**
 * CpuStats class, holds the information about the system-wide CPU usage.
 */
class CpuStats
{
    public:
        /**
         * Default constructor.
         */
        CpuStats(void);

        /**
         * Updates the internal data from /proc.
         */
        void update(void);

        /**
         * Returns the difference between the last two values
         * of the cpu time of the particular cpu usage mode
         * obtained with subsequent update calls.
         *
         * @param mode - cpu usage mode (type)
         *
         * @return cpu time difference of the particular cpu
         *         usage mode
         */
        unsigned long long getCpuTimeDiff(const CpuUsageMode mode) const;

        /**
         * Returns the difference between the sums of the cpu times
         * of all modes (types) obtained with subsequent update calls.
         *
         * The returned value is in fact the difference of the total
         * cpu time spent between these subsequent update calls.
         *
         * @return difference of the total cpu time spent between
         *         the last two subsequent update calls
         */
        unsigned long long getCpuTimeDiffTotal(void) const;

    private:

        /**
         * Cpu time values from the most recent update call.
         */
        CpuTime cpuTimeRec;

        /**
         * Cpu time values from the previous update call.
         */
        CpuTime cpuTimePrev;
};

} // namespace nr
} // namespace ccms

#endif /* __CCMS_NR_CPU_STATS_H__ */
